package com.projecy.storehouse.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.projecy.storehouse.entity.TheLibrary;
import com.projecy.storehouse.entity.TheLibraryDefault;
import com.projecy.storehouse.service.TheLibraryDefaultService;
import com.projecy.storehouse.service.TheLibraryService;
import com.projecy.storehouse.util.RepertoryResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (TheLibrary)表控制层
 *
 * @author maoyi
 * @since 2023-03-24 16:46:08
 */
@RestController
@RequestMapping("sys")
public class TheLibraryController {

    @Autowired
    TheLibraryService theLibraryService;

    @Autowired
    TheLibraryDefaultService theLibraryDefaultService;

/**
 * 申请
 */

    /**
     * @GetMapping("/productFile/list3")
     * 库存：已分配
     */

    /**
     * 添加出库申请
     *
     * @param theLibrary
     * @return
     */
    @PostMapping("/theLibrary/add")
    public ResponseEntity<Object> insertTheLibrary(@RequestBody TheLibraryAndDefault theLibrary){
        return theLibraryService.insertTheLibrary(theLibrary.theLibrary,theLibrary.list);
    }

    class TheLibraryAndDefault{
        private TheLibrary theLibrary;
        private List<TheLibraryDefault> list;
    }


    /**
     * 复核
     */

    /**
     * 入库申请查询
     * @return
     */
    @GetMapping("/theLibrary/list")
    public ResponseEntity<Object> seacherTheLibrary(){
        return theLibraryService.seacherTheLibrary("待审核");
    }

    /**
     * 出库申请明细
     * @param outId
     * @return
     */
    @GetMapping("/theLibrary/list1/{outId}")
    public ResponseEntity<Object> selectOneTheLibraryDefault(@PathVariable long outId){
        return RepertoryResultUtil.success(true,theLibraryDefaultService.list(new QueryWrapper<TheLibraryDefault>().eq("out_id",outId)));
    }

    /**
     * 出库申请复核
     * @param putId
     * @return
     */
    /**
     * 通过
     * @param outId
     * @return
     */
    @PostMapping("/theLibrary/check1/{outId}")
    public ResponseEntity<Object> checkTheLibraryOk(@PathVariable Long outId){
        return RepertoryResultUtil.success(true,theLibraryService.updateTheLibraryMark(outId,"已审核"));
    }
    /**
     * 不通过
     * @param outId
     * @return
     */
    @PostMapping("/theLibrary/check2/{outId}")
    public ResponseEntity<Object> checkTheLibrary(@PathVariable Long outId){
        return RepertoryResultUtil.success(true,theLibraryService.updateTheLibraryMark(outId,"未通过"));
    }



    /**
     * 查询
     */

    /**
     * 出库申请查询(状态)
     * @param mark
     * @return
     */
    @GetMapping("/theLibrary/list3/{mark}/{current}")
    public ResponseEntity<Object> seacherOutStorageMark(@PathVariable String mark){
        return RepertoryResultUtil.success(true,theLibraryService.seacherTheLibraryMark(mark));
    }

    /**
     * @GetMapping("/theLibrary/list1")
     */


}

